<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="ctrl/uploadCtrl.jsp" method="post" id="fileForm">
	新闻id:<input type="text" name="nid"><br>
	文件:<input type="file" name="file" id="file"> <br>
	<input type="hidden" name="fileName" id="fileName">
	<input type="submit" value="保存"> 
</form>
<div id="imgBox"></div>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>
<script type="text/javascript">
$(function(){
	$("#file").change(function(){
		$.ajaxFileUpload({
			url:"${pageContext.request.contextPath }/upload",
			type:"POST",
			fileElementId:"file",
			dataType:"json",
			success:function(data){
				console.log(data);
				if(data.flag){
					$("#fileName").val(data.fileName);
					$("#imgBox").append("<img src=http://localhost:82/image/"+data.fileName+" />")
				}
			},
			error:function(data){
				console.log(data)
			}
			
		});
	})
})

</script>
</body>
</html>